import java.util.Stack;

public class IsPopOrder {

    public static void main(String[] args) {
        int[] arr1 = {2,1,0};
        int[] arr2 = {1,2,0};
        System.out.println(IsPopOrder(arr1, arr2));
    }

    public static boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack  =new Stack<>();
        int j=0;
        for (int i = 0 ; i < pushA.length; i++) {
            stack.push(pushA[i]);

            while(!stack.isEmpty() && stack.peek() == popA[j] && j<popA.length ){
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }
}
